<?php

namespace App\Repositories\Admin;

use App\Models\Admin\AdminModel;
use App\Repositories\BaseRepository;

class AdminRepository extends BaseRepository
{
    protected $repository;

    public function __construct()
    {
        $this->repository = new AdminModel();
    }

    /**
     * 操作分页获取
     */
    public function getIndexList()
    {
        $models = $this->repository->orderBy('id','asc')
            ->paginate(20);
        $models->limit = 20;
        return $models;
    }

    public function setAdd($data)
    {
        return $this->repository->insertGetId($data);
    }

    public function setModify($data,$id)
    {
        return $this->repository->where('id',$id)
            ->update($data);
    }

    public function getShowOne($id)
    {
        return $this->repository->where('id',$id)->first();
    }

    /**
     * 密码更新
     */
    public function setPassword($id,$pwd)
    {
        return $this->repository->where('id',$id)
            ->update(array('pwd'=>$pwd));
    }

    /**
     * 通过name获取
     */
    public function getOneByName($name)
    {
        return $this->repository->where('name',$name)
            ->where('del',0)->first();
    }
}